//
//  XLArchorLeadView.m
//  XiangLove
//
//  Created by 李传坤 on 2018/4/17.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#import "XLArchorLeadView.h"
#import "UIImage+Gradient.h"
@interface XLArchorLeadView ()
@property (strong, nonatomic) UILabel *TopLabel;//label
@property (strong, nonatomic) UILabel *middleLabel;//恭喜label
@property (strong, nonatomic) UIView *alertView;

@property (strong, nonatomic) UIButton *GoTakeButton;
@property (strong, nonatomic) UIButton *dismissButton;



@end

@implementation XLArchorLeadView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        // 设置背影为透明色
        self.backgroundColor = [UIColor clearColor];
        [self addViews];
    }
    return self;
}
- (void)addViews{
    UIView *view = [[UIView alloc]init];
    view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    view.backgroundColor = [UIColor blackColor];
    view.alpha = 0.3;
    [self addSubview:view];
    
    _alertView = [[UIView alloc]init];
    _alertView.backgroundColor = [UIColor whiteColor];
    _alertView.layer.cornerRadius = 10;
    _alertView.center = CGPointMake(self.width/2,self.height/2);
    _alertView.frame = CGRectMake(SCREEN_WIDTH/2 - 130, SCREEN_HEIGHT/2 - 100, 280, 200);
    [self addSubview:_alertView];
    _TopLabel = [[UILabel alloc]init];
    _TopLabel.text = @"立即认证 轻松赚钱";
    _TopLabel.textColor = [UIColor blackColor];
    _TopLabel.textAlignment = NSTextAlignmentCenter;
    _TopLabel.font = [UIFont systemFontOfSize:18];
    [_alertView addSubview:_TopLabel];
    [_TopLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_alertView.mas_top).offset(20);
        make.centerX.equalTo(_alertView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(280, 40));
    }];
    _middleLabel = [[UILabel alloc]init];
    _middleLabel.text = @"最直观的视频聊天\n最快速的赚钱方式";
    _middleLabel.textColor = [UIColor lightGrayColor];
    _middleLabel.numberOfLines = 2;
    _middleLabel.textAlignment = NSTextAlignmentCenter;
    _middleLabel.font = [UIFont systemFontOfSize:16];
    [_alertView addSubview:_middleLabel];
    [_middleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_alertView.mas_centerY);
        make.centerX.equalTo(_alertView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(150, 40));
    }];
    
    _dismissButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_dismissButton setBackgroundImage:[UIImage imageNamed:@"Views_but_chacha_n"] forState:UIControlStateNormal];
    [_dismissButton addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
    [self.alertView addSubview:_dismissButton];
    [_dismissButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_alertView.mas_top);
        make.right.equalTo (_alertView.mas_right);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    
    _GoTakeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _GoTakeButton.frame =CGRectMake(40, 140, 200, 40);
    [_GoTakeButton addTarget:self action:@selector(push) forControlEvents:UIControlEventTouchUpInside];
    [_GoTakeButton setTitle:@"立即认证" forState:UIControlStateNormal];
    _GoTakeButton.layer.masksToBounds = YES;
    _GoTakeButton.layer.cornerRadius = 20;
    [self.alertView addSubview:_GoTakeButton];
    
    
}
- (void)push{
    [self dismiss];
    _block();
}
-(void)show{
    [_GoTakeButton setBackgroundImage:[UIImage gradientImageFromColors:@[HEXCOLOR(0xffc371), HEXCOLOR(0xff5f6d)] frame:_GoTakeButton.frame] forState:UIControlStateNormal];
    self.alpha = 0;
    [[[[UIApplication sharedApplication]delegate]window]addSubview:self];
    [UIView animateWithDuration:0.3
                          delay:0.0
                        options: UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         self.alpha = 1;
                     }
                     completion:^(BOOL finished){
                     }];
}
-(void)dismiss{
    [UIView animateWithDuration:0.3
                          delay:0.0
                        options: UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         self.alpha = 0;
                     }
                     completion:^(BOOL finished){
                         [self removeFromSuperview];
                     }];
}


@end
